package face.pay.web.cpn.cardInfo;

import face.pay.cpn.activityInfo.ICpnActivityInfoService;
import face.pay.cpn.cardInfo.ICpnCardInfoService;
import face.pay.dao.CpnMchServiceInfoDao;
import face.pay.entity.CpnCardInfo;
import face.pay.entity.CpnMchServiceInfo;
import face.pay.entity.UserInfo;
import face.pay.security.annotation.CurrentUser;
import face.pay.security.exception.BaseException;
import face.pay.util.ResultMessage;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Classname CpnCardInfoController
 * @Description JJL
 * @Date 2019/12/2 13:42
 */
@Controller
@RequestMapping("/cardInfo")
public class CpnCardInfoController {

    @Autowired
    private ICpnActivityInfoService cpnActivityInfoService;

    @Autowired
    private ICpnCardInfoService iCpnCardInfoService;

    @Autowired
    private CpnMchServiceInfoDao cpnMchServiceInfoDao;

  @RequestMapping("/index/{activityId}")
    public String indxe(@PathVariable("activityId") Integer activityId, Model model) {
        model.addAttribute("activityId",activityId);
        return "cpn/cpnCardInfo";
    }

    @RequestMapping("/queryData")
    @ResponseBody
    public PageData data(PageParam pageParam, CpnCardInfo cpnCardInfo, @CurrentUser UserInfo userInfo) throws BaseException {

        cpnCardInfo.setUserId(userInfo.getId());
        return this.cpnActivityInfoService.queryActivityCard(cpnCardInfo, pageParam, userInfo);

    }

    /**
     * 根据服务费展示用户可使用的折扣券
     * @param loginUser
     * @return
     */
    @RequestMapping("/serviceFee")
    @ResponseBody
    public ResultMessage queryMchServiceFee(@CurrentUser UserInfo loginUser){
        CpnMchServiceInfo record = new CpnMchServiceInfo();
        record.setUserId(loginUser.getId());
        CpnMchServiceInfo info = this.cpnMchServiceInfoDao.queryCpnMchServiceInfo(record);
        return ResultMessage.createSuccess(info);
    }

    /**
     * 编辑卡券信息
     * @param loginUser
     * @return
     */
    @RequestMapping("/editCardInfo")
    @ResponseBody
    public ResultMessage editCardInfo(@CurrentUser UserInfo loginUser,CpnCardInfo cpnCardInfo){
        return iCpnCardInfoService.modifyCardInfo(loginUser,cpnCardInfo);
    }

    /**
     * 制作卡券
     * @param loginUser
     * @param cpnCardInfo
     * @return
     */
    @RequestMapping("/startMakeCard")
    @ResponseBody
    public ResultMessage startMakeCard(@CurrentUser UserInfo loginUser,CpnCardInfo cpnCardInfo){
        return iCpnCardInfoService.startMakeCard(loginUser,cpnCardInfo);
    }
}
